<template>
  <div class="cotainer">
    <!--数据列表-->
    <div class="list-item clearfix">
      <el-col :span="4" v-for="(item, index) in dataList" :key="index">
        <el-card :body-style="{ padding: '0px' }" :id="item.id" @click="showDesc(item.id)">
           <!-- <img v-if="item.imageList.length === 0" src="https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png" class="image">-->
          <img :src="item.imageList[0]" class="image" onerror="./static/images/card/hamburger.png"/>
          <div class="card-desc" style="padding: 14px;">
            <span class="ellipsis">{{item.message}}</span>
            <div class="bottom clearfix">
              <time class="time ellipsis">{{item.descInfo}}</time>
              <el-button type="text" class="button" @click="showDesc(item.id)">查看详情</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </div>
    <!--分页-->
    <div class="block" style="display: none">
      <!--<span class="demonstration">调整每页显示条数</span>-->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[100, 200, 300, 400]"
        :page-size="100"
        layout="total, sizes, prev, pager, next, jumper"
        :total="400">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import {getAllMessages} from '../../api/message'
export default {
  name: 'CardComponent',
  data () {
    return {
      dataList: '',
      currentDate: new Date(),
      currentPage: 1
    }
  },
  mounted () {
    this.init()
  },
  methods: {
    /**
     * 初始化数据
     * @returns {Promise<void>}
     */
    init: async function () {
      const promise = await getAllMessages()
      console.log(promise)
      if (promise.status === 200) {
        this.dataList = promise.result
      }
    },
    /**
     * 显示详情
     * @param id
     */
    showDesc: function (id) {
      this.$router.replace(
        {
          path: 'details.do',
          name: 'messageDetails',
          query: {
            id: id
          }
        }
      )
      // this.reload()
    },
    /**
     * 显示第几页数据
     * @param val
     */
    handleSizeChange (val) {
      console.log(`每页 ${val} 条`)
    },
    /**
     * 当前页数据
     * @param val
     */
    handleCurrentChange (val) {
      console.log(`当前页: ${val}`)
    }
  }
}
</script>

<style scoped>
  .list-item{
    min-height: 1000px;
    min-width: 960px;
  }
  .el-col{
    min-width: 150px;
    width: calc(20% - 20px);
    height: 250px;
    margin: 15px 10px;
  }
  .el-card{
    cursor: pointer;
    background-color: #FAFAFA;
  }
  .time {
    display: block;
    font-size: 13px;
    color: #999;
    height: 20px;
    line-height: 18px;
  }

  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    width: 100%;
    height: 168px;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both
  }
  .el-pagination{
    display: flex;
    justify-content: flex-end;
  }
</style>
